#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define rep(i, a, b) for (int i = (a); i <= (b); i++)
#define per(i, a, b) for (int i = (a); i >= (b); i--)
#define endl '\n'
const int N = 3e5 + 5;

int n, m;
int head[N];
int ver[N << 1], W[N << 1], Next[N << 1], num;
void add(int u, int v, int w) {
  ++num;
  ver[num] = v;
  W[num] = w;
  Next[num] = head[u];
  head[u] = num;
}
struct Line {
  int x, y, z, len;
} q[N];
int st[N][20], dep[N], d[N], a[N];
void dfs(int u, int fu, int w) {
  st[u][0] = fu;
  dep[u] = dep[fu] + 1;
  d[u] = d[fu] + w;
  a[u] = w;
  for (int i = head[u]; i; i = Next[i]) {
    int v = ver[i];
    int w = W[i];
    if (v == fu) continue;
    dfs(v, u, w);
  }
}
void init_st() {
  rep(j, 1, 18) rep(i, 1, n) st[i][j] = st[st[i][j - 1]][j - 1];
}
int lca(int u, int v) {
  if (dep[u] < dep[v]) swap(u, v);
  int d = dep[u] - dep[v];
  per(j, 18, 0) if (d & (1 << j)) u = st[u][j];
  if (u == v) return u;
  per(j, 18, 0) if (st[u][j] != st[v][j]) u = st[u][j], v = st[v][j];
  return st[u][0];
}
int cnt[N], ans, tot;
void dfs2(int u, int fu) {
  for (int i = head[u]; i; i = Next[i]) {
    int v = ver[i];
    if (v == fu) continue;
    dfs2(v, u);
    cnt[u] += cnt[v];
  }
  if (cnt[u] == tot) ans = max(ans, a[u]);
}
bool check(int x) {
  rep(i, 0, n) cnt[i] = 0;
  int mxlen = 0;
  tot = 0;
  rep(i, 1, m) {
    if (q[i].len <= x) continue;
    tot++;
    mxlen = max(mxlen, q[i].len);
    cnt[q[i].x]++;
    cnt[q[i].y]++;
    cnt[q[i].z] -= 2;
  }
  if (tot == 0) return 1;
  ans = 0;
  dfs2(1, 0);
  return ans + x >= mxlen;
}
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> n >> m;
  rep(i, 2, n) {
    int u, v, w;
    cin >> u >> v >> w;
    add(u, v, w), add(v, u, w);
  }
  rep(i, 1, m) cin >> q[i].x >> q[i].y;
  dfs(1, 0, 0);
  init_st();
  rep(i, 1, m) {
    int z = lca(q[i].x, q[i].y);
    q[i].z = z;
    q[i].len = d[q[i].x] - d[z] + d[q[i].y] - d[z];
  }
  int l = 0, r = 3e8;
  while (l <= r) {
    int mid = (l + r) >> 1;
    if (check(mid))
      r = mid - 1;
    else
      l = mid + 1;
  }
  cout << l;
  return 0;
}